package java6699.dao.gui;

import java.sql.*;
import java.util.Objects;

public class DBUtil6699 {
    private static final String DRIVER;
    private static final String URL;
    private static final String USER;
    private static final String PW;

    private static final String DBNAME;

    static {
        //使用SQLite
            DRIVER = "com.mysql.jdbc.Driver";
            DBNAME = "db3";
            URL = "jdbc:mysql://localhost:3306/" + DBNAME;
            USER = "root";
            PW = "1234";
            try {
                Class.forName(DRIVER);
            } catch (ClassNotFoundException e) {
                e.getLocalizedMessage();
            }

    }


    public static Connection getConnection6699() throws Exception{
        return DriverManager.getConnection(URL,USER,PW);
    }

    public static void close(Statement stmt, Connection conn){
        try {
            Objects.requireNonNull(stmt).close();
            Objects.requireNonNull(conn).close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static void close(ResultSet rs, Statement stmt, Connection conn){
        try {
            Objects.requireNonNull(rs).close();
            Objects.requireNonNull(stmt).close();
            Objects.requireNonNull(conn).close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
